/*
 * Copyright (c) 2015 smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.web.property.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.smarthome.web.property.utils.UserHolder;

/**
 * 首页
 * @author KongXiangyu
 * @since 2015-08-05
 */
@Controller
@RequestMapping(value = "")
public class IndexController {

    @RequestMapping(value = { "/", "/index", "/default", "/main" }, method = { RequestMethod.GET, RequestMethod.POST })
    public String index(HttpServletRequest request, HttpServletResponse response) {
        return "/index";
    }
    
    @RequestMapping(value="change")
    public ModelAndView changeResidence(Long id){
    	ModelAndView  view = new ModelAndView("redirect:/index");
    	UserHolder.resetResidenceId(id);
    	return view;
    }

    @RequestMapping(value = "/login")
    public String init(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return "/login";
    }

    /**
     * 用户跳转JSP页面
     * 
     * 此方法不考虑权限控制
     * 
     * @param folder
     *            路径
     * @param jspName
     *            JSP名称(不加后缀)
     * @return 指定JSP页面
     */
    @RequestMapping("/{folder}/{jspName}")
    public String redirectJsp(@PathVariable String folder, @PathVariable String jspName) {
        return "/" + folder + "/" + jspName;
    }

}
